package com.itheima;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/helloServlet")//定义访问的地址   http://localhost:8080/helloServlet?username=Jack&password=12345
public class HelloServlet extends HttpServlet {
    /**
     *
     * @param req 负责获取浏览器请求，得到数据
     * @param resp 负责响应浏览器数据，写数据
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       //接收浏览器数据
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        System.out.println("收到请求："+username+"="+password);

        //响应浏览器数据
        resp.setHeader("content-type","text/html;charset=utf-8");
        PrintWriter writer = resp.getWriter();
        writer.println("login success!!登录成功");
        writer.flush();
    }
}
